#ifndef _SINGLETON_H_
#define _SINGLETON_H_

#include "NonCopyable.h"
#include "Assert.h"

template <typename T> 
class Singleton
	: public NonCopyable< T >
{
	public:

		Singleton( T* pInstance )
		{
			NULL_ASSERT( pInstance );
			ASSERT_MSG( ( m_instance == 0 ), "Instance is NOT NULL in Singleton!!" );
			m_instance = pInstance;
		}

		virtual ~Singleton( void ) 
		{  
			NULL_ASSERT( m_instance );  
			m_instance = 0;
		}

		// Accessors
		static T& GetInstance( void ) 
		{  
			NULL_ASSERT( m_instance );  
			return ( *m_instance );  
		}

		static T* GetInstancePtr( void ) 
		{  
			NULL_ASSERT( m_instance ); 
			return ( m_instance );  
		}

	private:

		static T* m_instance;
};

template <typename T> T* Singleton <T>::m_instance = 0;

#endif // end of _SINGLETON_H_